package com.nowcoder.Offer.Math;

import org.junit.Test;

public class MyPow {

    public double Power(double base, int exponent) {
        if(base == 0) return 0;
        long n = exponent;
        double res = 1.0;
        if(n<0){
            base = 1 / base;
            n = -n;
        }
        while( n > 0){
            if((n&0x1) == 1) res *= base;
            base *= base;
            n >>= 1;
        }
        return res;
    }

    @Test
    public void test(){
        System.out.println(Power(-2.0,3));
    }
}
